/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.economy.model;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


import ar.uba.fi.posgrado.common.model.AbstractDomainObject;
import ar.uba.fi.posgrado.common.model.User;

/**
 * Clase que representa una cobro efectuado.<br><br>
 * 
 * Un cobro se corresponde con una sola deuda.<br>
 * Una deuda puede ser cobrada en mas de un cobro, esto es, si el valor
 * del cobro es menor que el valor de la deuda (menos benef mas desc), se hace un cobro 
 * por lo q el usuario dijo y se deja saldo a pagar en la deuda (la prox vez
 * no se aplican mas desc/benef).<br>
 * Si el cobro es para una deuda en donde el saldo original y el a pagar
 * son distintos, significa el caso mencionado anteriormente, en donde los beneficios y 
 * descuentos no aplican mas.<br><br>
 * 
 * En caso de que el cobro sea por mas dinero que el de la deuda afectada,
 * entonces se dejara el sobrante en la cuenta corriente del cliente.<br><br>
 * 
 * @author nicolas.gonzalez
 * @see AbstractDomainObject
 */
@Entity
@Table(name = "COBRO")
@SuppressWarnings("serial")
public class Collect extends AbstractDomainObject {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "NOMBRE_USUARIO")
    private User user;
    
    @Column(name = "FECHA")
    private Date date;
    
    @Column(name = "VALOR")
    private Double value;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ID_TIPO_PAGO")
    private CollectType collectType;
    
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "ID_CLIENTE")
    private Customer customer;
    
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "ID_DEUDA", nullable = true)
    private Debt debt;
    
    // Motivo de del cobro ya se por caso especial o lo q fuere.
    @Column(name = "MOTIVO", length = 255, nullable = true)
    private String reason;
    
    @Column(name = "FACTURA", length = 40)
    private String code;
    
    /**
     */
    public Collect() {
    }

    /**
     * @param user
     * @param date
     * @param value
     * @param collectType
     * @param customer
     * @param debt
     */
    public Collect(User user, Date date, Double value, CollectType collectType,
            Customer customer, Debt debt) {
        this.user = user;
        this.date = date;
        this.value = value;
        this.collectType = collectType;
        this.customer = customer;
        this.debt = debt;
    }



    /**
     * @see ar.uba.fi.posgrado.common.model.AbstractDomainObject#getExcludedFields()
     */
    @Override
    public String[] getExcludedFields() {
        return new String[] {"user", "date", "value", "collectType", "customer", "debt", "code"};
    }

    /**
     * @return the user
     */
    public User getUser() {
        return this.user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return this.date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the value
     */
    public Double getValue() {
        return this.value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(Double value) {
        this.value = value;
    }

    /**
     * @return the collectType
     */
    public CollectType getCollectType() {
        return this.collectType;
    }

    /**
     * @param collectType the collectType to set
     */
    public void setCollectType(CollectType collectType) {
        this.collectType = collectType;
    }

    /**
     * @return the customer
     */
    public Customer getCustomer() {
        return this.customer;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * @return the debt
     */
    public Debt getDebt() {
        return this.debt;
    }

    /**
     * @param debt the debt to set
     */
    public void setDebt(Debt debt) {
        this.debt = debt;
    }

    /**
     * @return the reason
     */
    public String getReason() {
        return this.reason;
    }

    /**
     * @param reason the reason to set
     */
    public void setReason(String reason) {
        this.reason = reason;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return this.code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }
    

}
